package com.hospital.hospitalserver.util;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 门诊缴费生成支付凭证
 * */

public class PaymentItemReceiptGenerator {
    /**
     * 生成项目凭证码
     * 格式：PI + yyyyMMddHHmmss + 3位随机数
     */
    public static String generateItemReceiptNo() {
        // 获取当前时间，格式：yyyyMMddHHmmss
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String timestamp = sdf.format(new Date());

        // 生成3位随机数
        Random random = new Random();
        String randomNum = String.format("%03d", random.nextInt(1000));

        return "PI" + timestamp + randomNum;
    }

    /**
     * 批量生成项目凭证码（确保不重复）
     */
    public static List<String> generateBatchItemReceiptNos(int count) {
        Set<String> receiptNos = new HashSet<>();
        while (receiptNos.size() < count) {
            receiptNos.add(generateItemReceiptNo());
        }
        return new ArrayList<>(receiptNos);
    }
}
